package com.ruoyi.project.baozhi.box.service.impl;

import com.farshine.baokan.box.BoxControl;
import com.ruoyi.project.baozhi.box.service.BoxService;
//import com.ruoyi.project.baozhi.dept.domain.OrgDept;
import com.ruoyi.project.baozhi.dept.domain.OrgDept;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @program:baozhi
 * @description:
 * @create:2021-12-10
 */
@Service
public class BoxServiceImpl implements BoxService {
    @Value("${yingjian.ip}")
    private String ip;
    @Value("${yingjian.duankou}")
    private String duankou;
    @Value("${xiangzi.zuida}")
    private String zuida;
    @Value("${xiangzi.zuixiao}")
    private String zuixiao;

    public int bumenshuaxin(List<OrgDept> list) {

        System.out.println("部门刷新开始");
        BoxControl boxControl = null;
        try {
            boxControl = new BoxControl(ip, Integer.valueOf(duankou), Integer.valueOf(zuixiao), Integer.valueOf(zuida), (addr, lockIsOpen, btn1IsClick, btn2IsClick, cardNo) -> {

            });
            boxControl.setOnMessage((addr, lockIsOpen, btn1IsClick, btn2IsClick, cardNo) -> {
                System.out.println("onMessage.");
            });

            for (OrgDept orgDept : list) {
//                System.out.println("刷新部门名称");
                boxControl.setBoxText(Integer.valueOf(orgDept.getPn()), orgDept.getDeptName());
//                System.out.println("刷新第一块数量");
                boxControl.setBoxNumber(Integer.valueOf(orgDept.getPn()), 1, orgDept.getNeiShu(), 0x41);
//                System.out.println(orgDept.getNeiShu());
//                System.out.println("刷新第二块数量");
//                boxControl.setBoxNumber(Integer.valueOf(orgDept.getPn()), 2, orgDept.getWaiShu(), 0x41);
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (boxControl != null)
                boxControl.stop();
            System.out.println("部门刷新结束");
            return 1;
        }
    }
    public int bumenshuaxin_danwei(List<OrgDept> list) {

        System.out.println("部门名称刷新开始");
        BoxControl boxControl = null;
        try {
            boxControl = new BoxControl(ip, Integer.valueOf(duankou), Integer.valueOf(zuixiao), Integer.valueOf(zuida), (addr, lockIsOpen, btn1IsClick, btn2IsClick, cardNo) -> {

            });
            boxControl.setOnMessage((addr, lockIsOpen, btn1IsClick, btn2IsClick, cardNo) -> {
                System.out.println("onMessage.");
            });

            for (OrgDept orgDept : list) {
//                System.out.println("刷新部门名称");
                boxControl.setBoxText(Integer.valueOf(orgDept.getPn()), orgDept.getDeptName());
//                System.out.println("刷新第一块数量");
//                boxControl.setBoxNumber(Integer.valueOf(orgDept.getPn()), 1, orgDept.getNeiShu(), 0x41);
//                System.out.println(orgDept.getNeiShu());
//                System.out.println("刷新第二块数量");
//                boxControl.setBoxNumber(Integer.valueOf(orgDept.getPn()), 2, orgDept.getWaiShu(), 0x41);
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (boxControl != null)
                boxControl.stop();
            System.out.println("部门刷新结束");
            return 1;
        }
    }
    public int bumenshuaxin_shu(List<OrgDept> list) {

        System.out.println("部门数量刷新开始");
        BoxControl boxControl = null;
        try {
            boxControl = new BoxControl(ip, Integer.valueOf(duankou), Integer.valueOf(zuixiao), Integer.valueOf(zuida), (addr, lockIsOpen, btn1IsClick, btn2IsClick, cardNo) -> {

            });
            boxControl.setOnMessage((addr, lockIsOpen, btn1IsClick, btn2IsClick, cardNo) -> {
                System.out.println("onMessage.");
            });

            for (OrgDept orgDept : list) {
//                System.out.println("刷新部门名称");
//                boxControl.setBoxText(Integer.valueOf(orgDept.getPn()), orgDept.getDeptName());
//                System.out.println("刷新第一块数量");
                boxControl.setBoxNumber(Integer.valueOf(orgDept.getPn()), 1, orgDept.getNeiShu(), 0x41);
//                System.out.println(orgDept.getNeiShu());
//                System.out.println("刷新第二块数量");
//                boxControl.setBoxNumber(Integer.valueOf(orgDept.getPn()), 2, orgDept.getWaiShu(), 0x41);
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (boxControl != null)
                boxControl.stop();
            System.out.println("部门刷新结束");
            return 1;
        }
    }




}
